home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / ISSUE02 / TPACK / TPACK.ZIP / INILINK.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1995-06-01  |  25.8 KB  |  817 lines

  1. {------------------------------------------------------------------------------}
  2. {UNREGISTERED VERSION (6/1/95) PLEASE REDISTRIBUTE IN tPACK.ZIP!
  3.  This revision does not contain everything, nor are the exciting
  4.  DataSetReporter and ExtendedMenu[Item] components included.
  5.  Use SWREG#5906 to receive these, icons and a help file for $130.
  6.  You must register when using this code in a business application!
  7.  You'll receive a license to use this code in up to 50 copies of
  8.  any app you write. In turn you will get responsive e-mail
  9.  tech support and enhancements till I run out of registrations
  10.  or suggestions. Meanwhile.. enjoy the code. Bye! I'll make more.
  11.  {(C)'1995 Michael/Ax-Systems, 71560,1754@Compuserve.com}
  12. {------------------------------------------------------------------------------}
  13.  
  14. unit IniLink;
  15.  
  16. {THE POINT: To provide a delphiesque link to INI files using delphi's ini class as a
  17. starting point for a component by wrapping that class into a component.}
  18.  
  19. {FUNCTION: Think of it as an INI file you can visually put on a form. The file can be
  20. opened, closed manually or implicitly when accessed. The filehandele itself is accessible
  21. so you get direct access to TIniFile, plus the support offered by the ..Value Properties}
  22.  
  23. {IT GOES BEYOND THAT: the component is actually three layers.
  24. first we hook up to the file providing a host of features to automate setting the name
  25.   and path as well as providing defaults for the section name.
  26. the second layer adds 'retry' support for reading and writing to the ini file even when
  27.   at first the file is busy. in addition to the standard data types the second layer adds
  28.   support for the Char, Extended, TPoint and TRect types as well as the custom
  29.   TWindowPosValue type that can be used to store/restore control positions and/or
  30.   windowframes using built in procedures. you can access the section/entry item using the
  31.   second level's  ...Value properties.
  32. the third and final layers adds array syntax allowing you to access the supported datatypes
  33.   as arrays in a section. you can access items in a section by name using the third level's
  34.   ...Entry[Entry:String] properties.}
  35.  
  36. {TO USE: do nothing and once you place the component on a form you can access the default
  37. entry in the default section in the default ini file using any ...Value property.
  38. These properties don't show up in the object inspector as every entry in the file could be
  39. of any of the supported types but they are there. see the code below. }
  40.  
  41. interface
  42.  
  43. uses
  44.   SysUtils, Classes, Forms, IniFiles, WinTypes, Controls
  45.   ,Retry
  46.   ,PasUtils
  47.   ,UserInfo
  48.   ,UserWin;
  49.   {define condititional and code flPrivateDirectory}
  50.  
  51. type
  52.   TFileLocation = (flWindowsDir, flNamed, flSystemDir, flExePath); {defaults to flWindowsDir}
  53.   TNameType = (ftNamed, ftExeName, ftWindows, ftSystem, ftControl); {defaults to ftNamed (TEMP.INI)}
  54.  
  55.   TIniFileLinkFile = class(TDialogShell)
  56.     Handle: TIniFile;  {NOTE! Handle to TIniFile is herewith published!}
  57.   private
  58.     fFileName: PString;
  59.     fFilePath: PString;
  60.     fSection: PString;
  61.     fEntry: PString;
  62.  
  63.     fLeaveOpen: Boolean;
  64.     fNameType: TNameType;
  65.     fLocationType: TFileLocation;
  66.     fWindowsUserInfo: TWindowsUserInfo;
  67.   protected
  68.     procedure Notification(AComponent: TComponent; Operation: TOperation); Override;
  69.  
  70.     function GetIniFileName:string;
  71.     procedure SetIniFileName(const Value:String);
  72.     function GetFileName:String;
  73.     procedure SetFileName(const Value:String);
  74.     function GetFilePath:String;
  75.     procedure SetFilePath(const Value:String);
  76.  
  77.     function GetSection:String;
  78.     procedure SetSection(const Value:String);
  79.     function GetEntry:String;
  80.     procedure SetEntry(const Value:String);
  81.  
  82.     procedure SetFileLocation(Value: TFileLocation);
  83.     procedure SetNameType(Value: TNameType);
  84.     function StoreFileName:Boolean;
  85.     function StoreFilePath:Boolean;
  86.  
  87.   public
  88.     constructor Create(AOwner: TComponent); Override;
  89.     destructor Destroy; Override;
  90.     function FileSectionEntry:String;
  91.     function  IsOpen:Boolean;
  92.     procedure Open; {this WILL open the file!}
  93.     procedure Close;
  94.   published
  95.     property FileType: TNameType read fNameType write SetNameType;
  96.     property FileLocation: TFileLocation read fLocationType write SetFileLocation;
  97.     property IniFileName: String read GetIniFileName write SetIniFileName stored false;
  98.     property IniName: String read GetFileName write SetFileName stored StoreFileName;
  99.     property IniPath: String read GetFilePath write SetFilePath stored StoreFilePath;
  100.     property Section: String read GetSection write SetSection;
  101.     property Entry:   String read GetEntry write SetEntry;
  102.     property LeaveOpen: Boolean read fLeaveOpen write fLeaveOpen;      {trigger caching!}
  103.     property WindowsUserInfo: TWindowsUserInfo read fWindowsUserInfo write fWindowsUserInfo;
  104.   end;
  105.  
  106. {-------------------------------------------------------------------------}
  107. {  ADD ADDTL datatypes to the ini inteface                                }
  108. {-------------------------------------------------------------------------}
  109.  
  110.   TWindowPosValue = record
  111.     Top,Left,Height,Width: integer;
  112.     end;
  113.  
  114.   TIniActions = (iaEraseSection,iaEraseEntry
  115.  
  116.                 ,iaGetBool,iaSetBool
  117.                 ,iaGetInt,iaSetInt
  118.                 ,iaGetString,iaSetString
  119.  
  120.                 ,iaGetChar,iaSetChar
  121.                 ,iaGetExt,iaSetExt
  122.                 ,iaGetPoint,iaSetPoint
  123.                 ,iaGetRect,iaSetRect
  124.                 ,iaGetWPos,iaSetWPos
  125.                 );
  126.  
  127.   TIniFileLinkData = class(TIniFileLinkFile)
  128.   protected
  129.     fRetry: TRetry;
  130.     fAction: TIniActions;
  131.  
  132.     fString: PString;
  133.     fBool: Boolean;
  134.     fInteger: Longint;
  135.     fExt: Extended;
  136.     fRect: TRect;
  137.  
  138.   private
  139.     procedure DoAction(Sender:TObject);
  140.     procedure DoIniAction(Action:TIniActions);
  141.  
  142.     function GetBooleanValue:Boolean;
  143.     procedure SetBooleanValue(Value:Boolean);
  144.     function GetLongIntValue:LongInt;
  145.     procedure SetLongIntValue(Value:LongInt);
  146.     function GetStringValue:String;
  147.     procedure SetStringValue(const Value:String);
  148.     function GetCharacterValue:Char;
  149.     procedure SetCharacterValue(Value:Char);
  150.     function GetExtendedValue:Extended;
  151.     procedure SetExtendedValue(Value:Extended);
  152.     function GetPointValue:TPoint;
  153.     procedure SetPointValue(Value:TPoint);
  154.     function GetRectValue:TRect;
  155.     procedure SetRectValue(Value:TRect);
  156.     function GetWindowPosValue:TWindowPosValue;
  157.     procedure SetWindowPosValue(Value:TWindowPosValue);
  158.     function GetOnException:TRetryExceptionEvent;
  159.     procedure SetOnException(Value:TRetryExceptionEvent);
  160.  
  161.   public
  162.     constructor Create(AOwner: TComponent); override;
  163.     destructor Destroy; override;
  164.     procedure EraseSection;    {does what it says}
  165.     procedure EraseEntry;      {so does this}         {properties your code reads/sets}
  166.     procedure StoreControlPos(Control:TControl);
  167.     procedure LoadControlPos(Control:TControl);
  168.     property BooleanValue: Boolean read GetBooleanValue write SetBooleanValue stored false;
  169.     property LongIntValue: LongInt read GetLongIntValue write SetLongIntValue stored false;
  170.     property StringValue: String read GetStringValue write SetStringValue stored false;
  171.     property CharacterValue: char read GetCharacterValue write SetCharacterValue stored false;
  172.     property ExtendedValue: Extended read GetExtendedValue write SetExtendedValue stored false;
  173.     property PointValue: TPoint read GetPointValue write SetPointValue stored false;
  174.     property RectValue: TRect read GetRectValue write SetRectValue stored false;
  175.     property WindowPosValue: TWindowPosValue read GetWindowPosValue write SetWindowPosValue stored false;
  176.   published
  177.     property Retry:      TRetry read fRetry write fRetry;
  178.     property OnException: TRetryExceptionEvent read GetOnException write SetOnException;
  179.   end;
  180.  
  181.  
  182.   TIniFileLink = class(TIniFileLinkData)
  183.   protected
  184.     procedure Notification(AComponent: TComponent; Operation: TOperation); override;
  185.   private
  186.     constructor Create(AOwner: TComponent); override;
  187.       {needs a constructor or virtual methods will not kick in!}
  188.       {try to get this to work without a notification proc at this level! vcl seems
  189.       to be writte with that in mind? can't be!}
  190.  
  191.     function GetBooleanEntry(const aEntry:String):Boolean;
  192.     procedure SetBooleanEntry(const aEntry:String;Value:Boolean);
  193.     function GetLongIntEntry(const aEntry:String):LongInt;
  194.     procedure SetLongIntEntry(const aEntry:String;Value:LongInt);
  195.     function GetStringEntry(const aEntry:String):String;
  196.     procedure SetStringEntry(const aEntry:String;const Value:String);
  197.     function GetCharacterEntry(const aEntry:String):Char;
  198.     procedure SetCharacterEntry(const aEntry:String;Value:Char);
  199.     function GetExtendedEntry(const aEntry:String):Extended;
  200.     procedure SetExtendedEntry(const aEntry:String;Value:Extended);
  201.     function GetPointEntry(const aEntry:String):TPoint;
  202.     procedure SetPointEntry(const aEntry:String;Value:TPoint);
  203.     function GetRectEntry(const aEntry:String):TRect;
  204.     procedure SetRectEntry(const aEntry:String;Value:TRect);
  205.     function GetWindowPosEntry(const aEntry:String):TWindowPosValue;
  206.     procedure SetWindowPosEntry(const aEntry:String;Value:TWindowPosValue);
  207.   public
  208.     property BooleanEntry[const aEntry:String]: Boolean read GetBooleanEntry write SetBooleanEntry;
  209.     property LongIntEntry[const Entry:String]: LongInt read GetLongIntEntry write SetLongIntEntry;
  210.     property StringEntry[const Entry:String]: String read GetStringEntry write SetStringEntry;
  211.     property CharacterEntry[const Entry:String]: char read GetCharacterEntry write SetCharacterEntry;
  212.     property ExtendedEntry[const Entry:String]: Extended read GetExtendedEntry write SetExtendedEntry;
  213.     property PointEntry[const Entry:String]: TPoint read GetPointEntry write SetPointEntry;
  214.     property RectEntry[const Entry:String]: TRect read GetRectEntry write SetRectEntry;
  215.     property WindowPosEntry[const Entry:String]: TWindowPosValue read GetWindowPosEntry write SetWindowPosEntry;
  216.   published
  217.     end;
  218.  
  219. {-------------------------------------------------------------------------}
  220.  
  221. implementation
  222.  
  223. uses wincrt;
  224.  
  225. {-------------------------------------------------------------------------}
  226.  
  227. constructor TIniFileLinkFile.Create(AOwner: TComponent);
  228. begin
  229.   inherited Create(AOwner);
  230.   cx.SetIfFound(fWindowsUserInfo,TWindowsUserInfo);
  231.   fFileName := NullStr;
  232.   fFilePath := NullStr;
  233.   fSection := NullStr;
  234.   fEntry := NullStr;
  235.   Handle := nil;
  236. end;
  237.  
  238. destructor TIniFileLinkFile.Destroy;
  239. begin
  240.   Close;
  241.   DisposeStr(fEntry);
  242.   DisposeStr(fSection);
  243.   DisposeStr(fFilePath);
  244.   DisposeStr(fFileName);
  245.   inherited Destroy;
  246. end;
  247.  
  248. procedure TIniFileLinkFile.Notification(AComponent: TComponent; Operation: TOperation);
  249. begin
  250.   inherited Notification(AComponent, Operation);
  251.   if Operation = opRemove then begin
  252.     cx.NilIfSet(fWindowsUserInfo,AComponent);{say what you mean}
  253.     end;
  254. end;
  255.  
  256. {-------------------------------------------------------------------------}
  257.  
  258. procedure TIniFileLinkFile.SetFileName(const Value: String);
  259. begin
  260.   if Value <> fFileName^ then begin
  261.     Close;
  262.     AssignStr(fFileName,Value);
  263.     end;
  264. end;
  265.  
  266. function TIniFileLinkFile.StoreFileName:Boolean;
  267. begin
  268.   Result:= fNameType=ftNamed;
  269. end;
  270.  
  271. procedure TIniFileLinkFile.SetFilePath(const Value: String);
  272. begin
  273.   if Value <> fFilePath^ then begin
  274.     Close;
  275.     AssignStr(fFilePath,Value);
  276.     end;
  277. end;
  278.  
  279. function TIniFileLinkFile.StoreFilePath:Boolean;
  280. begin
  281.   Result:= fLocationType=flNamed;
  282. end;
  283.  
  284. {-------------------------------------------------------------------------}
  285.  
  286. procedure TIniFileLinkFile.SetFileLocation(Value: TFileLocation);
  287. begin
  288.   if Value <> fLocationType then begin
  289.     case fNameType of
  290.     ftWindows,
  291.     ftSystem,
  292.     ftControl: Value := flWindowsDir;
  293.     ftNamed: AssignStr(fFilePath,'');
  294.       end;
  295.     if Value <> fLocationType then begin
  296.       Close;
  297.       fLocationType := Value;
  298.       end;
  299.     end;
  300. end;
  301.  
  302. procedure TIniFileLinkFile.SetNameType(Value: TNameType);
  303. begin
  304.   if Value <> fNameType then begin
  305.     Close;
  306.     fNameType := Value;
  307.     case Value of
  308.     ftWindows,
  309.     ftSystem,
  310.     ftControl: fLocationType := flWindowsDir;
  311.     ftNamed: AssignStr(fFileName,'');
  312.       end;
  313.     end;
  314. end;
  315.  
  316. {-------------------------------------------------------------------------}
  317.  
  318. function TIniFileLinkFile.GetFileName: String;
  319. begin
  320.   Result:='';
  321.   case fNameType of
  322.   ftNamed: Result:=fFileName^; {as is, might be blank}
  323.   ftExeName: if cx.Designing then
  324.                Result:='(exename)';
  325.   ftWindows: Result:='Windows';
  326.   ftSystem:  Result:='System';
  327.   ftControl: Result:='Control';
  328.     end;
  329.   if not cx.Designing then
  330.     if (fNameType=ftExeName) or (fFileName^='') then
  331.       Result:=ExtractFileName(paramstr(0));
  332.   if Result='' then
  333.     Result:='Temp';
  334.   if Result<>fFileName^ then
  335.     AssignStr(fFileName,Result);
  336.   Result:=ChangeFileExt(Result,'.INI');
  337. end;
  338.  
  339. function TIniFileLinkFile.GetFilePath: String;
  340. begin
  341.   Result:='';
  342.   if (fLocationType in [flWindowsDir, flSystemDir]) then
  343.     cx.MakeIfNil(fWindowsUserInfo,TWindowsUserInfo);
  344.   case fLocationType of
  345.   flNamed: Result:=fFilePath^; {as is, might be blank}
  346.   flExePath:
  347.     if cx.Designing then
  348.       Result:='(exepath)'; {will set below at runtime}
  349.   flWindowsDir: Result:=fWindowsUserInfo.WindowsPath;
  350.   flSystemDir: Result:=fWindowsUserInfo.SystemPath;
  351.     end;
  352.   if not cx.Designing then
  353.     if (fLocationType=flExePath) or (fFilePath^='') then
  354.       Result:=ExtractFilePath(paramstr(0)); {default}
  355.   if Result='' then
  356.     Result:='C:\';
  357.   if not cx.Designing then
  358.     Result:=TrailingBackSlash(Result);
  359.   if Result<>fFilePath^ then
  360.     AssignStr(fFilePath,Result);
  361. end;
  362.  
  363. {-------------------------------------------------------------------------}
  364.  
  365. function TIniFileLinkFile.GetIniFileName: String;
  366. begin
  367.   Result:=IniPath+IniName; {read properties vis get functions}
  368. end;
  369.  
  370. procedure TIniFileLinkFile.SetIniFileName(const Value: String);
  371. begin
  372.   fLocationType:=flNamed;  {reset the flags so everything's consistent}
  373.   fNameType:=ftNamed;
  374.   AssignStr(fFilePath,TrailingBackSlash(ExtractFilePath(Value)));
  375.   AssignStr(fFileName,ExtractFileName(Value));
  376. end;
  377.  
  378. {-------------------------------------------------------------------------}
  379.  
  380. function TIniFileLinkFile.GetSection:String;
  381. begin
  382.   if fSection^='' then
  383.     Result:='(blank)'
  384.   else
  385.     Result:=fSection^;
  386. end;
  387.  
  388. procedure TIniFileLinkFile.SetSection(const Value:String);
  389. begin
  390.   AssignStr(fSection,Value);
  391. end;
  392.  
  393. function TIniFileLinkFile.GetEntry:String;
  394. begin
  395.   if fEntry^='' then
  396.     Result:='(blank)'
  397.   else
  398.     Result:=fEntry^;
  399. end;
  400.  
  401. procedure TIniFileLinkFile.SetEntry(const Value:String);
  402. begin
  403.   AssignStr(fEntry,Value);
  404. end;
  405.  
  406. {-------------------------------------------------------------------------}
  407.  
  408. function TIniFileLinkFile.FileSectionEntry:String;
  409. begin
  410.   Result:=IniFileName+'['+Section+']'+Entry;
  411. end;
  412.  
  413. {-------------------------------------------------------------------------}
  414.  
  415. function TIniFileLinkFile.IsOpen:Boolean;
  416. begin
  417.   Result:=Handle<>nil;
  418. end;
  419.  
  420. procedure TIniFileLinkFile.Open;
  421. begin
  422.   if cx.Designing then begin
  423.     if fNameType=ftExeName then
  424.       Raise Exception.Create('No ExeName available while designing!'+#13
  425.                             +'Specify another INI-name type for now.');
  426.     if (fLocationType in [flWindowsDir, flSystemDir]) then
  427.       cx.MakeIfNil(fWindowsUserInfo,TWindowsUserInfo);
  428.     end;
  429.   if not IsOpen then
  430.     Handle:=TIniFile.Create(GetIniFileName);
  431. end;
  432.  
  433. procedure TIniFileLinkFile.Close;
  434. begin
  435.   if Handle<>nil then
  436.     Handle.Free;
  437.   Handle:=nil;
  438. end;
  439.  
  440. {-------------------------------------------------------------------------}
  441. { TIniFileLinkData                                                        }
  442. {-------------------------------------------------------------------------}
  443.  
  444. constructor TIniFileLinkData.Create(AOwner: TComponent);
  445. begin
  446.   inherited Create(AOwner);
  447.   fRetry:=TRetry.Create;
  448.   fString:=NullStr;;
  449. end;
  450.  
  451. destructor TIniFileLinkData.Destroy;
  452. begin
  453.   DisposeStr(fString);
  454.   fRetry.Free;
  455.   inherited Destroy;
  456. end;
  457.  
  458. {-------------------------------------------------------------------------}
  459.  
  460. procedure TIniFileLinkData.DoAction(Sender:TObject);
  461. {this proc is called via the retry mechanism}
  462. {compond types based on StringValue will trigger a one level recursion on 'Get'.
  463.  this allows us to do the entire conversion inside the retry shell.}
  464. var
  465.   a1,a2:string;
  466. begin
  467.   Open; {no need to worry about recursing. open/close work via pointer=nil}
  468.  
  469.   with Handle do     {actions listed but not used will probably never trigger errors}
  470.     case fAction of                                               {see procs below}
  471.   iaEraseSection: EraseSection(Section);
  472.     iaEraseEntry:  WriteString(Section,Entry,'');
  473.        iaSetBool:    WriteBool(Section,Entry,fBool);
  474.         iaSetInt: WriteInteger(Section,Entry,fInteger);
  475.      iaSetString:  WriteString(Section,Entry,fString^);
  476.        iaGetBool:       fBool:=ReadBool(Section,Entry,false);
  477.         iaGetInt: fInteger:=ReadInteger(Section,Entry,0);
  478.      iaGetString:   AssignStr(fString,ReadString(Section,Entry,''));
  479.        iaGetChar: ;
  480.        iaSetChar: ;
  481.         iaGetExt: begin
  482.                   a1:=StringValue; {one recursion}
  483.                   fAction:=iaGetExt; {returns here in error}
  484.                   fExt:=StrToFloat(a1);
  485.                   end;
  486.         iaSetExt: ;
  487.       iaGetPoint: with fRect.Topleft do begin
  488.                   SplitString(StringValue,',',a1,a2);
  489.                   fAction:=iaGetPoint;
  490.                   x:=StrToInt(a1);
  491.                   y:=StrToInt(a2);
  492.                   end;
  493.       iaSetPoint: ;
  494.        iaGetRect: with fRect do begin
  495.                   SplitString(StringValue,',',a1,a2);
  496.                   fAction:=iaGetRect;
  497.                   Left:=StrToIntDef(a1,0);
  498.                   SplitString(a2,',',a1,a2);
  499.                   Top:=StrToIntDef(a1,0);
  500.                   SplitString(a2,',',a1,a2);
  501.                   Right:=StrToIntDef(a1,0);
  502.                   Bottom:=StrToIntDef(a2,0);
  503.                   end;
  504.        iaSetRect: ;
  505.        iaGetWPos: with TWindowPosValue(fRect) do begin
  506.                   SplitString(StringValue,',',a1,a2);
  507.                   fAction:=iaGetWPos;
  508.                   Top:=StrToIntDef(a1,0);
  509.                   SplitString(a2,',',a1,a2);
  510.                   Left:=StrToIntDef(a1,0);
  511.                   SplitString(a2,',',a1,a2);
  512.                   Height:=StrToIntDef(a1,0);
  513.                   Width:=StrToIntDef(a2,0);
  514.                   end;
  515.        iaSetWPos: ;
  516.     end;
  517.  
  518.   if not LeaveOpen then
  519.     Close;
  520. end;
  521.  
  522. procedure TIniFileLinkData.DoIniAction(Action:TIniActions);
  523. begin
  524.   fAction:=Action;
  525.   fRetry.RetryAction(DoAction);
  526. end;
  527.  
  528. {-------------------------------------------------------------------------}
  529.  
  530. function TIniFileLinkData.GetOnException:TRetryExceptionEvent;
  531. begin
  532.   Result:=fRetry.OnException;
  533. end;
  534.  
  535. procedure TIniFileLinkData.SetOnException(Value:TRetryExceptionEvent);
  536. begin
  537.   fRetry.OnException:=Value;
  538. end;
  539.  
  540. {-------------------------------------------------------------------------}
  541.  
  542. procedure TIniFileLinkData.EraseSection;
  543. begin
  544.   DoIniAction(iaEraseSection);
  545. end;
  546.  
  547. procedure TIniFileLinkData.EraseEntry;
  548. begin
  549.   DoIniAction(iaEraseEntry);
  550. end;
  551.  
  552. {-------------------------------------------------------------------------}
  553.  
  554. function TIniFileLinkData.GetBooleanValue:Boolean;
  555. begin
  556.   DoIniAction(iaGetBool);
  557.   Result:=fBool;
  558. end;
  559.  
  560. procedure TIniFileLinkData.SetBooleanValue(Value:Boolean);
  561. begin
  562.   fBool:=Value;
  563.   DoIniAction(iaSetBool);
  564. end;
  565.  
  566. {-------------------------------------------------------------------------}
  567.  
  568. function TIniFileLinkData.GetStringValue:String;
  569. begin
  570.   DoIniAction(iaGetString);
  571.   Result:=fString^;
  572. end;
  573.  
  574. procedure TIniFileLinkData.SetStringValue(const Value:String);
  575. begin
  576.   AssignStr(fString,Value);
  577.   DoIniAction(iaSetString);
  578. end;
  579.  
  580. {-------------------------------------------------------------------------}
  581.  
  582. function TIniFileLinkData.GetLongIntValue:LongInt;
  583. begin
  584.   DoIniAction(iaGetInt);
  585.   Result:=fInteger;
  586. end;
  587.  
  588. procedure TIniFileLinkData.SetLongIntValue(Value:LongInt);
  589. begin
  590.   fInteger:=Value;
  591.   DoIniAction(iaSetInt);
  592. end;
  593.  
  594. {-------------------------------------------------------------------------}
  595.  
  596. function TIniFileLinkData.GetCharacterValue:Char;
  597. begin
  598.   DoIniAction(iaGetString);
  599.   Result:=fString^[1];
  600. end;
  601.  
  602. procedure TIniFileLinkData.SetCharacterValue(Value:Char);
  603. begin
  604.   AssignStr(fString,Value);
  605.   DoIniAction(iaSetString);
  606. end;
  607.  
  608. {-------------------------------------------------------------------------}
  609.  
  610. function TIniFileLinkData.GetExtendedValue:Extended;
  611. begin
  612.   fExt:=0;
  613.   DoIniAction(iaGetExt);
  614.   Result:=fExt;
  615. end;
  616.  
  617. procedure TIniFileLinkData.SetExtendedValue(Value:Extended);
  618. begin
  619.   StringValue:=FloatToStr(Value);
  620. end;
  621.  
  622. {-------------------------------------------------------------------------}
  623.  
  624. function TIniFileLinkData.GetPointValue:TPoint;
  625. begin
  626.   DoIniAction(iaGetPoint);
  627.   Result:=fRect.TopLeft;
  628. end;
  629.  
  630. procedure TIniFileLinkData.SetPointValue(Value:TPoint);
  631. begin
  632.   with Value do
  633.     StringValue:=inttostr(x)+','+inttostr(y);
  634. end;
  635.  
  636. {-------------------------------------------------------------------------}
  637.  
  638. function TIniFileLinkData.GetRectValue:TRect;
  639. begin
  640.   DoIniAction(iaGetRect);
  641.   Result:=fRect;
  642. end;
  643.  
  644. procedure TIniFileLinkData.SetRectValue(Value:TRect);
  645. begin
  646.   with Value do
  647.     StringValue:=inttostr(Left)+','+inttostr(Top)+','
  648.                 +inttostr(Right)+','+inttostr(Bottom);
  649. end;
  650.  
  651. {-------------------------------------------------------------------------}
  652.  
  653. function TIniFileLinkData.GetWindowPosValue:TWindowPosValue;
  654. begin
  655.   DoIniAction(iaGetWPos);
  656.   Result:=TWindowPosValue(fRect);
  657. end;
  658.  
  659. procedure TIniFileLinkData.SetWindowPosValue(Value:TWindowPosValue);
  660. begin
  661.   with Value do
  662.     StringValue:=inttostr(Top)+','+inttostr(Left)+','
  663.                 +inttostr(Height)+','+inttostr(Width);
  664. end;
  665.  
  666. {-------------------------------------------------------------------------}
  667.  
  668. procedure TIniFileLinkData.StoreControlPos(Control:TControl);
  669. var
  670.   wp:TWindowPosValue;
  671. begin
  672.   with Control do begin
  673.     wp.Top:=Top;
  674.     wp.Left:=Left;
  675.     wp.Width:=Width;
  676.     wp.Height:=Height;
  677.     end;
  678.   WindowPosValue:=wp;
  679. end;
  680.  
  681. procedure TIniFileLinkData.LoadControlPos(Control:TControl);
  682. var
  683.   wp:TWindowPosValue;
  684. begin
  685.   wp:=WindowPosValue;
  686.   with wp do begin
  687.     Control.Top:=Top;
  688.     Control.Left:=Left;
  689.     Control.Width:=Width;
  690.     Control.Height:=Height;
  691.     end;
  692. end;
  693.  
  694. {-------------------------------------------------------------------------}
  695. { TIniFileLink                                                            }
  696. {-------------------------------------------------------------------------}
  697.  
  698. constructor TIniFileLink.Create(AOwner: TComponent);
  699. begin {required to activate virtual methods. would compile without but works wrong then!}
  700.   inherited Create(AOwner);
  701. end;
  702.  
  703. procedure TIniFileLink.Notification(AComponent: TComponent; Operation: TOperation);
  704. begin
  705.   inherited Notification(AComponent, Operation);
  706. end;
  707.  
  708. {-------------------------------------------------------------------------}
  709.  
  710. function TIniFileLink.GetBooleanEntry(const aEntry:String):Boolean;
  711. begin
  712.   Entry:=aEntry;
  713.   Result:=BooleanValue;
  714. end;
  715.  
  716. procedure TIniFileLink.SetBooleanEntry(const aEntry:String;Value:Boolean);
  717. begin
  718.   Entry:=aEntry;
  719.   BooleanValue:=Value;
  720. end;
  721.  
  722. {-------------------------------------------------------------------------}
  723. function TIniFileLink.GetLongIntEntry(const aEntry:String):LongInt;
  724. begin
  725.   Entry:=aEntry;
  726.   Result:=LongIntValue;
  727. end;
  728.  
  729. procedure TIniFileLink.SetLongIntEntry(const aEntry:String;Value:LongInt);
  730. begin
  731.   Entry:=aEntry;
  732.   LongIntValue:=Value;
  733. end;
  734.  
  735. {-------------------------------------------------------------------------}
  736. function TIniFileLink.GetStringEntry(const aEntry:String):String;
  737. begin
  738.   Entry:=aEntry;
  739.   Result:=StringValue;
  740. end;
  741.  
  742. procedure TIniFileLink.SetStringEntry(const aEntry:String;const Value:String);
  743. begin
  744.   Entry:=aEntry;
  745.   StringValue:=Value;
  746. end;
  747.  
  748. {-------------------------------------------------------------------------}
  749. function TIniFileLink.GetCharacterEntry(const aEntry:String):Char;
  750. begin
  751.   Entry:=aEntry;
  752.   Result:=CharacterValue;
  753. end;
  754.  
  755. procedure TIniFileLink.SetCharacterEntry(const aEntry:String;Value:Char);
  756. begin
  757.   Entry:=aEntry;
  758.   CharacterValue:=Value;
  759. end;
  760.  
  761. {-------------------------------------------------------------------------}
  762. function TIniFileLink.GetExtendedEntry(const aEntry:String):Extended;
  763. begin
  764.   Entry:=aEntry;
  765.   Result:=ExtendedValue;
  766. end;
  767.  
  768. procedure TIniFileLink.SetExtendedEntry(const aEntry:String;Value:Extended);
  769. begin
  770.   Entry:=aEntry;
  771.   ExtendedValue:=Value;
  772. end;
  773.  
  774. {-------------------------------------------------------------------------}
  775. function TIniFileLink.GetPointEntry(const aEntry:String):TPoint;
  776. begin
  777.   Entry:=aEntry;
  778.   Result:=PointValue;
  779. end;
  780.  
  781. procedure TIniFileLink.SetPointEntry(const aEntry:String;Value:TPoint);
  782. begin
  783.   Entry:=aEntry;
  784.   PointValue:=Value;
  785. end;
  786.  
  787. {-------------------------------------------------------------------------}
  788. function TIniFileLink.GetRectEntry(const aEntry:String):TRect;
  789. begin
  790.   Entry:=aEntry;
  791.   Result:=RectValue;
  792. end;
  793.  
  794. procedure TIniFileLink.SetRectEntry(const aEntry:String;Value:TRect);
  795. begin
  796.   Entry:=aEntry;
  797.   RectValue:=Value;
  798. end;
  799.  
  800. {-------------------------------------------------------------------------}
  801.  
  802. function TIniFileLink.GetWindowPosEntry(const aEntry:String):TWindowPosValue;
  803. begin
  804.   Entry:=aEntry;
  805.   Result:=WindowPosValue;
  806. end;
  807.  
  808. procedure TIniFileLink.SetWindowPosEntry(const aEntry:String;Value:TWindowPosValue);
  809. begin
  810.   Entry:=aEntry;
  811.   WindowPosValue:=Value;
  812. end;
  813.  
  814. {-------------------------------------------------------------------------}
  815.  
  816. end.
  817.